%Todo: Add Regularizer: need to change glmfit

addpath(genpath('/media/sda2/Users/Nermine/Desktop/code/sdp/gurobi301/gurobi_mex_v1.20'));
addpath(genpath('./cplexint100'));
%clc;
clear all;
close all;
format short;

numFeatures     = 4     ;       % number of features
load('../../data/dat_0.mat');
numTrain          = length(xTrain_o(:,1)) ;
testdata    = [xTest_o yTest_o];%For validation Only. Use graph data separately.
trainingdata    = [xTrain_o(1:numTrain,:) yTrain_o(1:numTrain)];

%preprocessing to alleviate the probability values.
index_train_preprocess1 = find(trainingdata(:,4) > -1);
trainingdata = trainingdata(index_train_preprocess1,:);
numTrain = length(trainingdata(:,1));

numTrain = 6000;
trainingdata = trainingdata(1:numTrain,:);


numUnlabeled = 6;  %Number of unlabeled nodes
indexHandpick = [15509;15510; 15517; 15502; 15505;15507];
unLabeled   = [xTest_o(indexHandpick,:) yTest_o(indexHandpick)];
%Data from Google for d_{i,j}
dists_obtained_from_GMAPquery = [...
2547 266;
3911 456;
982 243;
1912 257;
1569 245;
1984 292;
4265 541;
5839 679;
6884 753;
4914 574;
308 49;
2588 291;
3529 408;
1429 209;
4118 516];

% Casting the data in a format amenable to Gurobi/ampl/Cplex.
C = zeros(numUnlabeled,numUnlabeled);    %the distance matrix
k=1;
for i=1:numUnlabeled
    for j=1:i-1
        C(i,j) = dists_obtained_from_GMAPquery(k,1);
        C(j,i) = C(i,j);
        k = k+1;
    end
end
C = C/100; %Scaling.

%  To check sanity of solver : 1542361/259 numUnlabeled=6
%  C = [0 12  1000  1000  9 16; %origianl std TRP
%         12  0 19 12  1000 15;
%       1000 19  0 21  1000 17; 
%          1000 12 21  0 10 16;
%       9  1000  1000 10  0 10;
%           16 15 17 16 10  0];
% q = ones(numUnlabeled,1); 


C0 = 1; C1 = 1; C2 = 1; %Coefficients of each of the terms in the obj.

%OPTION1: MINLP: via AMPL+BONMIN
%joint_ampl; % run ampl ampl_combined.pl on commandline

%OPTION2: 2 Step Control: via Glmfit+MILP(Cplex/Gurobi)
flag_step1_twoStep = 1;
flag_step2_twoStep = 1;
flag_cplex = 0;
twostep_method_gurobi;

%Plots to understand the situation
flag_reverseEngg_plots      = 1;
flag_plotFeatures2Dtraining = 0;
flag_plotFeatures2Dtest     = 0;
index_featureA              = 1;
index_featureB              = 2;
dataManagement;